package com.lagou;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

//mapper输入参数类型：LongWritable, Text
//mapper输出参数类型：IntWritable, NullWritable
public class SortMapper extends Mapper<LongWritable, Text, IntWritable, NullWritable> {
    /*
    接收文本内容，每一行为一个数字，转换为IntWritable类型后直接输出
     */
    //定义全局变量，避免每次执行map方法都执行此操作
    IntWritable num = new IntWritable();
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //接收文本内容，转换为IntWritable类型
        num.set(Integer.parseInt(value.toString()));
        //直接输出即可
        context.write(num, NullWritable.get());
    }
}
